﻿using System;
using System.Collections.ObjectModel;
using Wulong.Phone.Dianping.Constants;
using Wulong.Phone.Dianping.Models;
using Wulong.Phone.Dianping.Utils;

namespace Wulong.Phone.Dianping.Services
{
    /// <summary>
    /// Facade class for all services
    /// </summary>
    public static class DianpingService
    {
        public static IObservable<Channel> ObservableChannel(
            string cityCode)
        {
            return ChannelService.ObservableChannel(cityCode);
        }

        public static IObservable<GroupOn> ObservableHotGroupOn(
            string cityPinyin, bool receivedAll=false)
        {
            return GroupOnService.ObservableHotGroupOn(cityPinyin, receivedAll);
        }

        public static IObservable<Promotion> ObservablePromotion(
            string cityCode,
            int page = 1,
            int mode = 2,
            int mcId=-1,
            int mrId=-1)
        {
            return PromotionService
                .ObservablePromotion(cityCode, page, mode, mcId, mrId);
        }

        public static City DefaultCity()
        {
            return CityService.DefaultCity();
        }

        public static IObservable<City> ObservableCity()
        {
            return CityService.ObservableCity();
        }

        public static IObservable<City> FindCity(string keyword)
        {
            return CityService.FindCity(keyword);
        }

        public static City GetCity(string code)
        {
            return CityService.GetCity(code);
        }

        public static City GetCity(
            string code, 
            ObservableCollection<City> cities)
        {
            return CityService.GetCity(code, cities);
        }

        public static bool GetMyCityCode(
            out string code
            )
        {
            return AppSettings.TryGetSetting(
                CommonConstants.MyCityStorageKey,
                out code);
        }

        public static IObservable<Merchant> MerchantsByChannel(
            ChannelEnum channel,
            string cityCode,
            int page = 1,
            RankOrderEnum rank = RankOrderEnum.Default)
        {
            return MerchantService.ObservableMerchant("0", ((int)channel).ToString(), cityCode, page, rank.ToString());
        }

        public static IObservable<Merchant> MerchantsByCircle(
            string circleId,
            string cityCode,
            int page,
            RankOrderEnum rank)
        {
            return MerchantService
                .ObservableMerchant(circleId, "0", cityCode, page, rank.ToString());
        }

        public static IObservable<Promotion> ObservablePromotionItem(string cityId, string promoId)
        {
            return PromotionService.ObservabelPromotionItem(cityId, promoId);
        }

        public static string SendToMyPhoneLink(string cityCode, string promoId)
        {
            return PromotionService.SendToMyPhoneLink(cityCode, promoId);
        }

        public static IObservable<SearchSuggestion> ObservableSuggestion(
            string keywords, string cityCode, ChannelEnum channelId)
        {
            return SearchService.ObservableSuggestion(keywords, cityCode, ((int)channelId).ToString());
        }

        public static IObservable<Merchant> ObservableSearch(
            string keywords,
            string cityCode,
            ChannelEnum channelId,
            int page = 1,
            string circleId = "",
            RankOrderEnum rank = RankOrderEnum.Default
            )
        {
            return MerchantService.ObservableSearch(
                keywords,
                cityCode,
                ((int)channelId).ToString(),
                circleId,
                page,
                ((int)rank).ToString());
        }

        public static IObservable<Review> ObservableReview(
            string merchantId, 
            string cityCode, 
            int page=1)
        {
            return ReviewService.ObservableReview(merchantId, cityCode, page);
        }

        public static IObservable<Merchant> ObservableMerchantItem(
            string cityCode,
            string merchantId)
        {
            return MerchantService.ObservableMerchantItem(cityCode, merchantId);
        }

        public static Channel GetChannel(
            int channelId,
            ObservableCollection<Channel> channels)
        {
            return ChannelService.GetChannel(channelId, channels);
        }

        public static IObservable<string> ObservableFullReview(string url)
        {
            return ReviewService.ObservableFullReview(url);
        }

        public static string TransitMapHtml(
            string cityName, 
            string fromAddr, 
            string toAddr)
        {
            return BaiduMapHelper.TransitMapHtml(cityName, fromAddr, toAddr);
        }
    }
}
